﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufInputControl.h"

namespace gnuf {
    class Info;

    class GNUF_BASE_EXPORT IListControlHandler
        : public IInputControlHandler
    {
    public:
        virtual int onGetCurrentIndex() const = 0;
        virtual void onCurrentIndexChanged(int) = 0;
    };
    
    class GNUF_BASE_EXPORT ListControlAdpatation
        : public InputControlAdaptation
    {
    protected:
        ListControlAdpatation();
        virtual ~ListControlAdpatation();

        //
        // Inherits from InputControlAdaptation...
        virtual void onVisibilityChanged(bool) override {}
        virtual void onSelectionChanged(bool) override {}
        
    public:
        virtual void onCurrentIndexChanged(int) = 0;
    };
    
    class GNUF_BASE_EXPORT ListControl
        : public InputControl
    {
        CANNOT_COPY_OR_ASSIGN(ListControl)
    public:
        static const EItemType Type;
        ListControl(IListControlHandler *, bool, std::vector< gcmp::OwnerPtr< Info > > &, gcmp::OwnerPtr<Info>&);
        virtual ~ListControl();
        
        void setCurrentIndex(int, const ListControlAdpatation * trigger = nullptr);
        const std::vector<gcmp::OwnerPtr< Info >>& GetList() { return m_list; }
        inline const Info* info() const { return m_info.get(); }

    private:
        const bool m_readonly;
        std::vector< gcmp::OwnerPtr< Info > > m_list;
        gcmp::OwnerPtr<Info> m_info;
    };

}
